#include<iostream>
#include<cmath>
using namespace std;
using ll = long long;
int main()
{
    ll y, z; cin >> y >> z;
    ll ret = 1e13;
    for (ll i = 100000; i <= 999999; i++)
    {
        ll x = (i * 1e6 + y);
        ret = min( abs(x - z), ret);
    }
    cout << ret << endl;
    return 0;
}